package com.wn.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie-set")
public class CookieSetServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Cookie 对象存储在客户端浏览器
        // 需要通过response对象，发送响应数据时候携带cookie

        // 创建Cookie对象
       Cookie cookie = new Cookie("userId","1001001");
       response.addCookie(cookie);   // 响应头中会增加一个Set-Cookie 存储 key-value数据
    }
}